﻿Public Class NamespaceForm

    Private _RefNamespace As Core.Functions.MetisNamespace

    Sub New(ByVal RefNamespace As Core.Functions.MetisNamespace)
        InitializeComponent()
        _RefNamespace = RefNamespace
        txtName.Text = _RefNamespace.Name
        txtAnnotation.Text = _RefNamespace.Annotation
        _RefNamespace.BeginEdit()
    End Sub

    Public ReadOnly Property [Namespace]() As Core.Functions.MetisNamespace
        Get
            Return _RefNamespace
        End Get
    End Property

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        _RefNamespace.EndEdit()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        _RefNamespace.CancelEdit()
    End Sub

    Private Sub txtName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtName.TextChanged
        If _RefNamespace.IsEditMode Then
            Try
                _RefNamespace.Name = txtName.Text
                txtName.BackColor = SystemColors.Window
                ttName.RemoveAll()
                btnOK.Enabled = _RefNamespace.IsModified
            Catch ex As Core.Exceptions.MetisNameException
                txtName.BackColor = Color.Salmon
                ttName.SetToolTip(txtName, ex.Message)
                btnOK.Enabled = False
            End Try
        End If

    End Sub

    Private Sub txtAnnotation_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAnnotation.TextChanged
        If _RefNamespace.IsEditMode Then
            _RefNamespace.Annotation = txtAnnotation.Text
        End If
    End Sub
End Class